package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;

import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description
 * @author: ZXX-挚爱
 * @time: 2023/6/14 17:43
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /** @author ZXX-挚爱
    * @Description 订单搜索
    * @Dete 19:28 2023/6/14
    * @Param [ordersPageQueryDTO]
    * @return com.sky.result.Result<com.sky.result.PageResult>
    **/

    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){

        PageResult pageResult=orderService.conditionSearch(ordersPageQueryDTO);
        return  Result.success(pageResult);
    }
    /** @author ZXX-挚爱
    * @Description 查看各个状态的订单数量
    * @Dete 20:05 2023/6/14
    * @Param
    * @return com.sky.result.Result<com.sky.vo.OrderStatisticsVO>
    **/

    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO orderStatisticsVO =orderService.statistics();
        return Result.success(orderStatisticsVO);
    }

    /** @author ZXX-挚爱
    * @Description 查询订单详情
    * @Dete 20:09 2023/6/14
    * @Param [id]
    * @return com.sky.result.Result<com.sky.vo.OrderVO>
    **/

    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO> details(@PathVariable("id") Long id){
        OrderVO orderVO=orderService.details(id);
        return Result.success(orderVO);
    }


    /** @author ZXX-挚爱
    * @Description 接单
    * @Dete 20:21 2023/6/14
    * @Param [ordersConfirmDTO]
    * @return com.sky.result.Result
    **/

    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /** @author ZXX-挚爱
    * @Description 拒单
    * @Dete 20:28 2023/6/14
    * @Param [ordersRejectionDTO]
    * @return com.sky.result.Result
    **/


    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception{
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    /** @author ZXX-挚爱
    * @Description 取消订单
    * @Dete 20:43 2023/6/14
    * @Param [ordersCancelDTO]
    * @return com.sky.result.Result
    **/

    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception{
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    /** @author ZXX-挚爱
    * @Description 配送订单
    * @Dete 21:13 2023/6/14
    * @Param [id]
    * @return com.sky.result.Result
    **/

    @PutMapping("/delivery/{id}")
    @ApiOperation("配送订单")
    public Result delivery(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success();
    }

    /** @author ZXX-挚爱
    * @Description 完成订单
    * @Dete 21:14 2023/6/14
    * @Param [id]
    * @return com.sky.result.Result
    **/

    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable Long id){
        orderService.complete(id);
        return Result.success();
    }



}
